/*
============================================================================
 Name        : LastFmPlugin.h
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : CLastFmPlugin declaration
============================================================================
*/

#ifndef __CPODCASTPLUGIN__
#define __CPODCASTPLUGIN__

#include "PluginInterface.h"		//CPluginInterface
#include "StreamBuffer.h"			//StreamBuffer.h
#include "AudioscrobblerEngine.h"	//MAudioscrobblerObserver
#include "MStreamBufferObserver.h"	//MStreamBufferObserver


class CEikMenuPane;
class CLastFmPlayer;
class CLastFmUI;

// An implementation of the CPluginInterface definition
class CLastFmPlugin :	public CPluginInterface,
						public MStreamBufferObserver,
						public MAudioscrobblerObserver
{
public:
	// Standardised safe construction which leaves nothing the cleanup stack.
	static CLastFmPlugin* NewL(TAny* aInitParams);
	// Destructor	
	~CLastFmPlugin();

private:
	// Construction
	CLastFmPlugin(TAny* aParams);
	void ConstructL();


public: //from CPluginInterface
	const TDesC& GetMenuText();
	TInt GetMenuCommand();
	void AddExtraMenu(CEikMenuPane* aMenuPane);
	void HandleCommandL(TInt aCommand);
	//TKeyResponse HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);

	void Draw(CWindowGc& aGc, const TRect& aRect) const;

	void SetContainer(MPluginContainer* aContainer);

	void Activate();
	void Deactivate();

	//Colors
	TRgb BackBorderColor() const;
	TRgb BackShadowColor() const;
	TRgb BackColor() const;
	TRgb InsideBorderColor() const;
	TRgb InsideColor() const;
	TRgb ForeColor() const;


public: //from MPlayerAdapter
	void PlayL();
	void PauseL() {};
	void StopL();

	TBool IsReadyToPlay();
	TBool IsReadyToPause() { return EFalse; };
	TBool IsReadyToStop();

	TInt Volume();
	void SetVolume(TInt aVolume);


private: //from MStreamBufferObserver
	void BufferStateChanged(TBool aIsBuffering, TInt aPercent);
	void Finished();


private: //from MAudioscrobblerObserver
	void PlaylistRequestedL(TPlaylist* aPlaylist);
	void RunError(const TDesC& aErrorDesc);


private: //new functions
	void AddResourceFileL();
	void LoginL();
	void HandshakeL();
	void PlayCurrentTrackL();
	void PlayCurrentTrack2L();
	
	void ReadUsernameL();
	void WriteUsernameL();

	static TInt OnImageIsReady(TAny* aAny);

private:
	//Plugin state
	enum TState
	{
		EStateNotReady,		//Not ready to play
		EStateReadyToPlay,	//Ready to play
		EStateHandshaking,	//Making handshake
		EStatePlaying,		//Playing
		EStateFailed		//Failed	
	} iState;

	// Parameters taken from client
	CPluginInterface::TPluginInterfaceInitParams* iInitParams;

	//Resource compiled file id
	TInt iOffset;

	//Player
	CLastFmPlayer* iLastFmPlayer;

	//UI class manager
	CLastFmUI* iLastFmUI;

	//Login
	TBuf<255> iUsername;
	TBuf<255> iPassword;

	//Playlist
	TPlaylist* iPlaylist;
	TInt iCurrentTrack;
	TBuf<500> iMetadata;

	//Audioscrobbler engine
	CAudioscrobblerEngine* iScrobblerEngine;

	//Callback after image is ready to be drawn
	TCallBack iOnImageReadyCallback;
};  

#endif
